#ifndef _ENCRYPTION_H
#define _ENCRYPTION_H 1

#include <string>
#include <cstdio>
#include <openssl/evp.h>

namespace encryption {
   const int IV_LENGTH = EVP_MAX_IV_LENGTH;
   const int KEY_LENGTH = 32; /* for AES256 */
   
   void init();
   void fini();
   std::string bin2hex(const unsigned char *buf, const size_t len);
   void hex2bin(const std::string hex, unsigned char *buf, const size_t len);
   bool load_keyfile(const std::string &keyfile);
   bool load_keyfile(FILE *fkeyfile);
   bool load_key(const std::string &hexkey);
   void random_iv(unsigned char new_iv[IV_LENGTH]);
   bool encrypt(FILE *fin, FILE *fout, unsigned char iv[IV_LENGTH]);
   bool decrypt(FILE *fin, FILE *fout, unsigned char iv[IV_LENGTH]);
   bool decrypt_mem(unsigned char iv[IV_LENGTH], const unsigned char *cipher,
                    const unsigned clen, unsigned char **plain, unsigned *plen);
}

#endif
